package com.javaee.controller;

import com.javaee.entity.Teacher;
import com.javaee.entity.TeachingClass;
import com.javaee.entity.User;
import com.javaee.service.TeacherService;
import com.javaee.service.TeachingClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/Teacher")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;

    @PostMapping
    public Result create(@RequestBody Teacher teacher) {
        boolean flag = teacherService.add(teacher);
        String msg = flag ? "创建成功" : "创建失败，请重试！";
        return new Result(flag ? Code.ADD_OK:Code.ADD_ERR,flag,msg);
    }
    @GetMapping("/{id}")
    public Result getByName(@PathVariable Integer id){
        Teacher teacher= teacherService.getById(id);
        Integer code = teacher != null ? Code.GET_OK : Code.GET_ERR;
        String msg = teacher != null ? "查询成功" : "数据查询失败，请重试！";
        return new Result(code,teacher,msg);
    }
}
